//
//  CorgiEmoticonPageView.swift
//  weibo
//
//  Created by Corgi on 17/3/30.
//  Copyright © 2017年 cocoaHangTou. All rights reserved.
//

import UIKit

class CorgiEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        
        let flowLayout = UICollectionViewFlowLayout()
        
        super.init(frame: frame, collectionViewLayout: flowLayout)
        
        flowLayout.minimumLineSpacing = 0
        
        flowLayout.minimumInteritemSpacing = 0
        
        flowLayout.scrollDirection = .horizontal
        
        flowLayout.itemSize = CGSize(width: screenWidth, height: 216 - 35)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    fileprivate func setupUI() {
        
        //backgroundColor = THEMECOLOR
        
        dataSource = self
        
        register(CorgiEmoticonPageViewCell.self, forCellWithReuseIdentifier: "Cell_ID")
    }
}

extension CorgiEmoticonPageView: UICollectionViewDataSource {

    func numberOfSections(in collectionView: UICollectionView) -> Int {
        
        return CorgiEmoticonTools.shared.allEmoticons.count
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return CorgiEmoticonTools.shared.allEmoticons[section].count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell_ID", for: indexPath) as! CorgiEmoticonPageViewCell
     
        cell.indexPath = indexPath
        
        cell.emoticons = CorgiEmoticonTools.shared.allEmoticons[indexPath.section][indexPath.item]
        
        return cell
    }
}
